﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading;

using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.StorageClient;

using SBPweb.PlAzureNet.Server.Library.Processes;

namespace SBPweb.PlAzureNet.Cloud.LotteryEngine
{

    public class WorkerRole : RoleEntryPoint
    {

        private const int TickInterval = 60000;
        
        private LotteryProcess process = new LotteryProcess();

        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("SBPweb.PlAzureNet.Cloud.LotteryEngine entry point called", "Information");

            while (true)
            {
                process.Tick();
                
                Thread.Sleep(TickInterval);
            }
        }

        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            process.Start();

            return base.OnStart();
        }

        public override void OnStop()
        {
            process.Stop();

            base.OnStop();
        }

    }

}